﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using UCL.Powersource.Analysis;
using UCL.Powersource.Statistics;
using UCL.Powersource.Statistics.CodeIndex;

namespace UCL.Powersource
{
    public interface IReportingContextStrategy
    {
         Guid Guid { get; }
         Func<ITfsTeamProjectConfiguration,bool > ITfsTeamProjectConfiguration_IsSelected { get; }
         Func<ITimeFrame, bool> ITimeFrame_IsSelected { get; }
         Func<IStatistic, bool> IStatistic_IsSelected { get; }
    }

    [Export(typeof(IReportingContextStrategy))]
    [DataContract(IsReference=true)]
    public sealed class AllSelected_ReportingContextStrategy : IReportingContextStrategy
    {
        private Guid _Guid = new Guid("2E6C4C03-CD40-4187-AFFD-1999926DED81");
        public Guid Guid { get { return _Guid; } }

        private Func<ITfsTeamProjectConfiguration, bool> _ITfsTeamProjectConfiguration_IsSelected = (a) => false;
        private Func<ITimeFrame, bool> _ITimeFrame_IsSelected = (a) => false;
        private Func<IStatistic, bool> _IStatistic_IsSelected = (a) => false;

        public Func<ITfsTeamProjectConfiguration, bool> ITfsTeamProjectConfiguration_IsSelected { get { return _ITfsTeamProjectConfiguration_IsSelected; } }
        public Func<ITimeFrame, bool> ITimeFrame_IsSelected { get { return _ITimeFrame_IsSelected; } }
        public Func<IStatistic, bool> IStatistic_IsSelected { get { return _IStatistic_IsSelected; } }
    }

    [Export(typeof(IReportingContextStrategy))]
    [DataContract(IsReference = true)]
    public sealed class Default_ReportingContextStrategy : IReportingContextStrategy
    {
        private Guid _Guid = new Guid("488D9F3F-5438-4463-ABA4-5B095A3FDB8E");
        public Guid Guid { get { return _Guid; } }

        public static string DefaultProjectNameStartsWith = "Default";

        private Func<ITfsTeamProjectConfiguration, bool> _ITfsTeamProjectConfiguration_IsSelected = (a) => (a.UniqueName ?? DefaultProjectNameStartsWith).StartsWith(DefaultProjectNameStartsWith);
        private Func<ITimeFrame, bool> _ITimeFrame_IsSelected = (a) => a.TimeFrameType==TimeFrameTypes.Release;
        private Func<IStatistic, bool> _IStatistic_IsSelected = (a) => false;

        public Func<ITfsTeamProjectConfiguration, bool> ITfsTeamProjectConfiguration_IsSelected { get { return _ITfsTeamProjectConfiguration_IsSelected; } }
        public Func<ITimeFrame, bool> ITimeFrame_IsSelected { get { return _ITimeFrame_IsSelected; } }
        public Func<IStatistic, bool> IStatistic_IsSelected { get { return _IStatistic_IsSelected; } }
    }

    [Export(typeof(IReportingContextStrategy))]
    [DataContract(IsReference = true)]
    public sealed class WorkItemSummary_ReportingContextStrategy : IReportingContextStrategy
    {
        private Guid _Guid = new Guid("D9530088-3E3D-412A-8B79-9065C911D9E8");
        public Guid Guid { get { return _Guid; } }

        public static string DefaultProjectNameStartsWith = "Default";

        private Func<ITfsTeamProjectConfiguration, bool> _ITfsTeamProjectConfiguration_IsSelected = (a) => false;
        private Func<ITimeFrame, bool> _ITimeFrame_IsSelected = (a) => a.TimeFrameType == TimeFrameTypes.Release;
        private Func<IStatistic, bool> _IStatistic_IsSelected = (a) => (a is TasksDone || a is TasksInProgress || a is TasksRemoved ||
                                                                        a is TasksReopened || a is TasksToDo || 
                                                                        a is PBckLogItemsCommitted || a is PBckLogItemsDone || a is PBckLogItemsRemoved ||
                                                                        a is PBckLogItemsReopened || a is DonePBITestsNumb);

        public Func<ITfsTeamProjectConfiguration, bool> ITfsTeamProjectConfiguration_IsSelected { get { return _ITfsTeamProjectConfiguration_IsSelected; } }
        public Func<ITimeFrame, bool> ITimeFrame_IsSelected { get { return _ITimeFrame_IsSelected; } }
        public Func<IStatistic, bool> IStatistic_IsSelected { get { return _IStatistic_IsSelected; } }
    }

    [Export(typeof(IReportingContextStrategy))]
    [DataContract(IsReference = true)]
    public sealed class PBISummary_ReportingContextStrategy : IReportingContextStrategy
    {
        private Guid _Guid = new Guid("1ACE62F8-AF8C-4211-BADE-35260B02196A");
        public Guid Guid { get { return _Guid; } }

        public static string DefaultProjectNameStartsWith = "Default";

        private Func<ITfsTeamProjectConfiguration, bool> _ITfsTeamProjectConfiguration_IsSelected = (a) => false;
        private Func<ITimeFrame, bool> _ITimeFrame_IsSelected = (a) => a.TimeFrameType == TimeFrameTypes.Release;
        private Func<IStatistic, bool> _IStatistic_IsSelected = (a) => (a is PBckLogItemsCommitted || a is PBckLogItemsDone || a is PBckLogItemsRemoved ||
                                                                        a is PBckLogItemsReopened || a is DonePBITestsNumb);

        public Func<ITfsTeamProjectConfiguration, bool> ITfsTeamProjectConfiguration_IsSelected { get { return _ITfsTeamProjectConfiguration_IsSelected; } }
        public Func<ITimeFrame, bool> ITimeFrame_IsSelected { get { return _ITimeFrame_IsSelected; } }
        public Func<IStatistic, bool> IStatistic_IsSelected { get { return _IStatistic_IsSelected; } }
    }

    [Export(typeof(IReportingContextStrategy))]
    [DataContract(IsReference = true)]
    public sealed class TaskSummary_ReportingContextStrategy : IReportingContextStrategy
    {
        private Guid _Guid = new Guid("8BDC039C-DFD0-4409-BF14-9C4E5409CCC4");
        public Guid Guid { get { return _Guid; } }

        public static string DefaultProjectNameStartsWith = "Default";

        private Func<ITfsTeamProjectConfiguration, bool> _ITfsTeamProjectConfiguration_IsSelected = (a) => false;
        private Func<ITimeFrame, bool> _ITimeFrame_IsSelected = (a) => a.TimeFrameType == TimeFrameTypes.Release;
        private Func<IStatistic, bool> _IStatistic_IsSelected = (a) => (a is TasksDone || a is TasksInProgress || a is TasksRemoved ||
                                                                        a is TasksReopened || a is TasksToDo);

        public Func<ITfsTeamProjectConfiguration, bool> ITfsTeamProjectConfiguration_IsSelected { get { return _ITfsTeamProjectConfiguration_IsSelected; } }
        public Func<ITimeFrame, bool> ITimeFrame_IsSelected { get { return _ITimeFrame_IsSelected; } }
        public Func<IStatistic, bool> IStatistic_IsSelected { get { return _IStatistic_IsSelected; } }
    }

    [Export(typeof(IReportingContextStrategy))]
    [DataContract(IsReference = true)]
    public sealed class InvalidWorkSummary_ReportingContextStrategy : IReportingContextStrategy
    {
        private Guid _Guid = new Guid("744860CD-0D08-4362-95D1-4D6D815EB594");
        public Guid Guid { get { return _Guid; } }

        public static string DefaultProjectNameStartsWith = "Default";

        private Func<ITfsTeamProjectConfiguration, bool> _ITfsTeamProjectConfiguration_IsSelected = (a) => false;
        private Func<ITimeFrame, bool> _ITimeFrame_IsSelected = (a) => a.TimeFrameType == TimeFrameTypes.Release;
        private Func<IStatistic, bool> _IStatistic_IsSelected = (a) => (a is InvalidPBckLogItems || a is InvalidTasks || a is PBIwithNoTests);

        public Func<ITfsTeamProjectConfiguration, bool> ITfsTeamProjectConfiguration_IsSelected { get { return _ITfsTeamProjectConfiguration_IsSelected; } }
        public Func<ITimeFrame, bool> ITimeFrame_IsSelected { get { return _ITimeFrame_IsSelected; } }
        public Func<IStatistic, bool> IStatistic_IsSelected { get { return _IStatistic_IsSelected; } }
    }

    [Export(typeof(IReportingContextStrategy))]
    [DataContract(IsReference = true)]
    public sealed class PlanningSummary_ReportingContextStrategy : IReportingContextStrategy
    {
        private Guid _Guid = new Guid("791EA052-82BC-4799-A035-9E075832FBBA");
        public Guid Guid { get { return _Guid; } }

        public static string DefaultProjectNameStartsWith = "Default";

        private Func<ITfsTeamProjectConfiguration, bool> _ITfsTeamProjectConfiguration_IsSelected = (a) => false;
        private Func<ITimeFrame, bool> _ITimeFrame_IsSelected = (a) => a.TimeFrameType == TimeFrameTypes.Release;
        private Func<IStatistic, bool> _IStatistic_IsSelected = (a) => (a is VelocityStatistics || a is TotalEffortDone || a is StartDateTotalEffort ||
                                                                        a is FinishDateTotalEffort || a is PercentageOfPlannedEffortDone || a is AccelerationStatistics);

        public Func<ITfsTeamProjectConfiguration, bool> ITfsTeamProjectConfiguration_IsSelected { get { return _ITfsTeamProjectConfiguration_IsSelected; } }
        public Func<ITimeFrame, bool> ITimeFrame_IsSelected { get { return _ITimeFrame_IsSelected; } }
        public Func<IStatistic, bool> IStatistic_IsSelected { get { return _IStatistic_IsSelected; } }
    }

    [Export(typeof(IReportingContextStrategy))]
    [DataContract(IsReference = true)]
    public sealed class CodeSummary_ReportingContextStrategy : IReportingContextStrategy
    {
        private Guid _Guid = new Guid("ADBCAFC0-42A6-4964-970A-A1064F746DCD");
        public Guid Guid { get { return _Guid; } }

        public static string DefaultProjectNameStartsWith = "Default";

        private Func<ITfsTeamProjectConfiguration, bool> _ITfsTeamProjectConfiguration_IsSelected = (a) => false;
        private Func<ITimeFrame, bool> _ITimeFrame_IsSelected = (a) => a.TimeFrameType == TimeFrameTypes.Release;
        private Func<IStatistic, bool> _IStatistic_IsSelected = (a) => (a is NumberOfClassesStats || a is NumberOfMethodsStats || a is DepthOfInheritance ||
                                                                        a is RFCStatisticAverage || a is RFCStatisticMaximum || a is RFCStatisticMedian ||
                                                                        a is RFCStatisticMinimum);

        public Func<ITfsTeamProjectConfiguration, bool> ITfsTeamProjectConfiguration_IsSelected { get { return _ITfsTeamProjectConfiguration_IsSelected; } }
        public Func<ITimeFrame, bool> ITimeFrame_IsSelected { get { return _ITimeFrame_IsSelected; } }
        public Func<IStatistic, bool> IStatistic_IsSelected { get { return _IStatistic_IsSelected; } }
    }


}
